define(function (require) {
    require('share');
    var utils = require('utils');
    var obj = {
        init: function () {
            this.getData()
        },
        getData: function () {
            var id = utils.getUrlParam('id');
            if (!id) {
                utils.goBack()
            }
            var index = utils.tipsLoading("数据加载中");
            var rest = $.restPost('boxGroup/listBox', {
                boxGroupId: id,
                userId: JSON.parse(utils.getLocalStorage('userinfo')).id
            });
            rest.done(function (msg, data) {
                utils.tipsClose(index);
                data.boxStatusVOs.forEach(function (e) {
                    switch (e.status) {
                        case 0:
                            $('#exist .count').text('待取：' + e.count);
                            break;
                        case 1:
                            $('#free .count').text('空：' + e.count);
                            break;
                        case 2:
                            $('#abnormal .count').text('异常：' + e.count);
                            break;
                    }
                })
                $("#box-list").html(utils.tmpl("tmpl", data));
            });
            rest.fail(function (msg) {
                utils.tipsClose(index);
                utils.tipsError(msg);
            });
        },
        goToDetail: function () {
            utils.goTo('cabinet-detail.html?id=' + $(this).data('id') + '&name=' + $(this).data('name'));
        }
    };

    $(function () {
        obj.init();
        $('#box-list').on('click', 'li', obj.goToDetail);
        $('#refresh').click(obj.getData)
    })

});